var param_platform_code = $.url().param('platform_code');
var param_type_code = $.url().param('type_code');
var param_league_code = $.url().param('league_code');
var param_date = $.url().param('date');

getMatchInfo(param_platform_code, param_type_code, param_league_code, param_date);

function getMatchInfo(platform_code, type_code, league_code, date) {
    $("#match_loading_zone").show();
    $("#match_data_zone").hide();
    $("#match_error_zone").hide();
    var token = getCookie('csrftoken');
    $.ajax({
        // url: '/football/get_match_info/',
        url: 'http://8.134.215.241:9080/jyb/core/plat/acquireplattypeleateamvss',
        type: 'POST',
        headers:{'X-CSRFToken': token, "Content-Type": "application/json"},
        data: JSON.stringify({'baseDate': date, 'platCode': platform_code, 'typeCode': type_code, 'leaCode': league_code}),
        success: function(data) {
            let jsonData = data['result']['platTypeLeaTeamVsVoList'];
            console.log(jsonData);
            let listHtml = "";
            listHtml = listHtml + '<div class="self_common_zone">';
            jsonData.forEach((item, index) => {
                let team_left_code = item['teamCodeLeft'];
                let team_right_code = item['teamCodeRight'];
                let team_left_name = item['teamNameLeft'];
                let team_right_name = item['teamNameRight'];
                listHtml = listHtml + '<div data-date="' + date + '" data-left="' + team_left_code + '" data-right="' + team_right_code + '" data-platform="' + platform_code + '" data-type="' + type_code + '" data-league="' + league_code + '" onclick="goToPlayPage(this)" class="self_common_item self_common_item_size_normal self_letter_spacing_2">';
                listHtml = listHtml + '<span>';
                listHtml = listHtml + team_left_name + " - " + team_right_name;
                listHtml = listHtml + '</span>';
                listHtml = listHtml + '</div>';
            });
            listHtml = listHtml + '</div>';
            $("#match_data_zone").html(listHtml);
            $("#match_loading_zone").hide();
            $("#match_error_zone").hide();
            $("#match_data_zone").show();
        },
        error: function() {
            $("#match_loading_zone").hide();
            $("#match_data_zone").hide();
            $("#match_error_zone").show();
        }
    });
}

function goToPlayPage(element) {
    const platform_code = element.dataset.platform;
    const type_code = element.dataset.type;
    const league_code = element.dataset.league;
    const left_code = element.dataset.left;
    const right_code = element.dataset.right;
    const date = element.dataset.date;
    goToOtherPage('./play.html?platform_code=' + platform_code + '&type_code=' + type_code + '&league_code=' + league_code + '&left_code=' + left_code + '&right_code=' + right_code + '&date=' + date );
}

function navigateToPlatformPage() {
    goToOtherPage('./platform.html?date=' + param_date );
}

function navigateToTypePage() {
    goToOtherPage('./type.html?platform_code=' + param_platform_code + '&date=' + param_date);
}

function navigateToLeaguePage() {
    goToOtherPage('./league.html?platform_code=' + param_platform_code + '&type_code=' + param_type_code + '&date=' + param_date);
}

